#!/usr/bin/env python

from google.appengine.ext import webapp
from models.library import Library
import bulkupdate

# This controller handles the
# generation of the front page.

class PutHandler(webapp.RequestHandler):

    def get(self):
        
        job = LibraryNormalizer()
        job.start()
        
        output = "Started background task to normalize all libraries."
        
        self.response.out.write(output)
    

class LibraryNormalizer(bulkupdate.BulkUpdater):

    def get_query(self):
        return Library.all()
    
    def handle_entity(self, entity):
        entity.normalize()
        self.put(entity)
